<template>
  <h2>和为：{{sum}}</h2>
  <button @click="sum++">和+1</button>
  <hr>
  <h2>当前的信息为：{{msg}}</h2>
  <button @click="msg+='！'">修改信息</button>
  <hr>
  <h2>个人信息</h2>
  <h2>姓名：{{person.name}}</h2>
  <h2>年龄：{{person.age}}</h2>
  <h2>薪资：{{person.job.j1.salary}}K</h2>
  <button @click="person.name+='~'">修改信息</button>
  <button @click="person.age++">增加年龄</button>
  <button @click="person.job.j1.salary++">涨薪</button>
</template>

<script>
import {ref, watch} from 'vue'
export default {
    name: "Demo",
    setup(){
      //数据
      let sum=ref(0)
      let msg=ref('你好啊')
      let person=ref({
        name:'张三',
        age:18,
        job:{
          j1:{
            salary:20
          }
        }
      })

      watch(sum,(newValue,oldValue)=>{
        console.log("sum值发生了改变",newValue,oldValue)
      })

      watch(person,(newValue,oldValue)=>{
        console.log("sum值发生了改变",newValue,oldValue)
      })

      //对于ref生成的对象类型数据检测，使用deep，或者直接person.value进行监测
      /*watch(person,(newValue,oldValue)=>{
        console.log("person值发生了改变",newValue,oldValue)
      },{deep:true})*/


      /*watch(person.value,(newValue,oldValue)=>{
        console.log("person值发生改变啦~~~~",newValue,oldValue)
      })*/



      //返回一个对象（常用）
      return{
          sum,
          msg,
          person
      }
    },
}
</script>

<style scoped>

</style>
